package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.StPlan;
import com.ruoyi.system.service.IStPlanService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 任务计划Controller
 * 
 * @author wmao
 * @date 2024-07-19
 */
@Controller
@RequestMapping("/system/stplan")
public class StPlanController extends BaseController
{
    private String prefix = "system/stplan";

    @Autowired
    private IStPlanService stPlanService;

    @RequiresPermissions("system:stplan:view")
    @GetMapping()
    public String stplan()
    {
        return prefix + "/stplan";
    }

    /**
     * 查询任务计划列表
     */
    @RequiresPermissions("system:stplan:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(StPlan stPlan)
    {
        startPage();
        List<StPlan> list = stPlanService.selectStPlanList(stPlan);
        return getDataTable(list);
    }

    /**
     * 导出任务计划列表
     */
    @RequiresPermissions("system:stplan:export")
    @Log(title = "任务计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(StPlan stPlan)
    {
        List<StPlan> list = stPlanService.selectStPlanList(stPlan);
        ExcelUtil<StPlan> util = new ExcelUtil<StPlan>(StPlan.class);
        return util.exportExcel(list, "任务计划数据");
    }

    /**
     * 新增任务计划
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存任务计划
     */
    @RequiresPermissions("system:stplan:add")
    @Log(title = "任务计划", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(StPlan stPlan)
    {
        return toAjax(stPlanService.insertStPlan(stPlan));
    }

    /**
     * 修改任务计划
     */
    @RequiresPermissions("system:stplan:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        StPlan stPlan = stPlanService.selectStPlanById(id);
        mmap.put("stPlan", stPlan);
        return prefix + "/edit";
    }

    /**
     * 修改保存任务计划
     */
    @RequiresPermissions("system:stplan:edit")
    @Log(title = "任务计划", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(StPlan stPlan)
    {
        return toAjax(stPlanService.updateStPlan(stPlan));
    }

    /**
     * 删除任务计划
     */
    @RequiresPermissions("system:stplan:remove")
    @Log(title = "任务计划", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(stPlanService.deleteStPlanByIds(ids));
    }
}
